﻿using SaiLing.Domain.Specification;
using SaiLing.SingleSignOn.Domain.Entities.System;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;

namespace SaiLing.SingleSignOn.Domain.Specifications.System
{
   public class PositionSpecification : ISpecification<Position>
    {
        private string Name { get; set; }

        public PositionSpecification(string name)
        {
            Name = name;
        }

        public Expression<Func<Position, bool>> SatisfiedBy()
        {
            Specification<Position> spec = new TrueSpecification<Position>();
            spec &= new DirectSpecification<Position>(x => !x.LogicRemove);
            if (!string.IsNullOrWhiteSpace(Name))
                spec &= new DirectSpecification<Position>(x => x.FullName.Contains(Name) || x.ShortName.Contains(Name));

            return spec.SatisfiedBy();
        }
    }
}
